<%- include header %>
<!-- 主题内容start -->
<table class="table table-bordered table-striped table-condensed table-hover">
    <tr>
        <th class="span3" colspan="6"><h4 style="text-align: center">所有注册用户(总人数：<%- count %>人|当前页：<%- page.num %>/<%- page.pageCount %>页)</h4></th>
    </tr>
    <tr>
        <th class="span3">账号</th>
        <th class="span2">昵称</th>
        <th class="span3">邮箱</th>
        <th class="span3">微信</th>
        <th class="span2">性别</th>
        <th class="span2">年龄</th>
        <th class="span2">状态</th>
        <th class="span2">操作</th>
    </tr>
    <% datas.forEach(function(data,index){ %>
    <tr>
        <td>
            <%- data.username %>
        </td>
        <td>
            <%- data.nickname %>
        </td>
        <td>
            <%- data.email %>
        </td>
        <td>
            <%- data.wechat %>
        </td>
        <% if(data.gender==1){ %>
        <td>
            男
        </td>
        <% }else{ %>
        <td>
            女
        </td>
        <% } %>
        <td>
            <%- data.age %>
        </td>
        <% if(data.state==0){ %>
        <td>
            正常
        </td>
        <% }else{ %>
        <td>
            禁用
        </td>
        <% } %>
        <td>
            <% if(data.state==0){ %>
                <a class="btn btn-danger btn-small" onclick="updateUserState('<%- data._id %>',1)">禁用</a>
            <% }else{ %>
                <a class="btn btn-success btn-small" onclick="updateUserState('<%- data._id %>',0)">恢复</a>
            <% } %>
        </td>
    </tr>
    <% }) %>
</table>
<div class="span12">
    <div id="page1"></div>
</div>

<!-- 主题内容end -->
<%- include footer %>
<script>
    function updateUserState(id,state){
        var prompt=confirm("你确定更改用户状态吗？？");

        if(prompt){

            window.location.href="/manager/updateUserState?id="+id+"&state="+state;
        }
    }
    $(function(){
        //获得浏览器参数

        $.extend({
            getUrlVars: function(){
                var vars = [];
                var hash;
                var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
                console.log(hashes);
                for(var i = 0; i < hashes.length; i++){
                    hash = hashes[i].split('=');
                    vars.push(hash[0]);
                    vars[hash[0]] = hash[1];
                }
                return vars;
            },
            getUrlVar: function(name){
                return $.getUrlVars()[name];
            }
        });

        //封装浏览器参数
        var composeUrlParams=function(){
            var param='';
            $.each($.getUrlVars(), function(i, item) {
                if(item!='num'){
                    var val=$.getUrlVar(item);
                    if(val) param += "&" + item+"="+val;
                }
            });
            return param;
        }
        var options = {
            currentPage:<%- page.num %>,                //当前页，css样式同其他页不同
            totalPages:<%- page.pageCount %>,           //总页数
            numberOfPages:5,                            //导航最多显示页数
            pageUrl: function(type, page, current) {    //页面跳转
                if(page!=<%- page.num %>){
                    return "/manager/registerUser?num="+ page+composeUrlParams();
                }

            }
        }
        $('#page1').bootstrapPaginator(options);
    })
</script>
